<?php

namespace app\common\model;

use think\Model;


class Prizes extends Model
{

    

    

    // 表名
    protected $name = 'prizes';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'ac_type_text',
        'image_url'
    ];

    public function getImageUrlAttr($value,$data)
    {
        if($data['image']==null){
            return null;
        }
        if(strstr($data['image'],'http')){
            return $data['image'];
        }else{
            return request()->domain().$data['image'];
        }
    }

    public function getAcTypeList()
    {
        return ['1' => '积分抽奖', '2' => '积分兑换'];
    }
    public function getAcTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['activity_id']) ? $data['activity_id'] : '');
        $list = $this->getAcTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function activity()
    {
        return $this->belongsTo('Activity', 'activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function depot()
    {
        return $this->belongsTo('Depot', 'depot_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
